﻿Chenxin.UI.ShowListArchive = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListArchive.ashx',
    createSearch: function() {
        return new Chenxin.UI.ShowListArchiveSearch({
            scope: this,
            afterGetParamJson: function(data) {
                // data.op = 'search';
            }
        });
    },
    createGrid: function() {
        var objPg = this;
        this.CompactGrid = new Chenxin.UI.Pagination({
            actionUrl: this.actionUrl + "?op=search&showtype=20",
            pageSize: 10,
            renderTo: 'archive_table_compact',
            id: 'archive_compact',
			autoLoad:false
        });
        this.TrdditionGrid = new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=search&showtype=10',
            pageSize: 50,
            height:400,
            renderTo: 'archive_table_trddition',
            hasCheckBox: false,
            scope: this,
            autoLoad: false,
            modelId: 'RecordId',
            id: 'archive_trddition',
            title: '签约报备',
            onClick: function(id) {
                objPg.currentArchiveInfo = this.grid.getCurrentRecord();
            },
            columns: {
                IsAnswer: {
                    width: 40,
                    head: "回复",
                    renderer: function(val, field, row) {
                        if (val == true) {
                            return '<input type="checkbox" disabled="disabled" checked="checked"/>';
                        }
                        return '<input type="checkbox" disabled="disabled"/>'
                    },
                    sortable: true,
                    sortField: "a.IsAnswer"
                },
                BargainTime: {
                    width: 125,
                    head: "签约时间",
                    sortable: true
                },
                LoanTime: {
                    width: 125,
                    head: "签贷款时间",
                    sortable: true
                },
                BargainType: {
                    width: 60,
                    head: "签约方式"
                },
                SignPlace: {
                    width: 140,
                    head: "签约地点",
                    style: "text-align:left"
                },
                BargainCompanyName: {
                    width: 80,
                    head: "合同所属",
                },
                HouseAddress: {
                    width: 320,
                    head: "房屋地址",
                    style: "text-align:left"
                },
                DepartName: {
                    width: 80,
                    head: "报备门店",
                    sortable: true
                },
                Employee: {
                    width: 80,
                    head: "报备人"
                },
                TotalPrice: {
                    width: 100,
                    head: "合同标的"
                },
                LoanInfo: {
                    width: 100,
                    head: "贷款情况"
                },
                CustomerName: {
                    width: 80,
                    head: "主贷人"
                },
                IDNum: {
                    width: 140,
                    head: "身份证"
                },
                LonggevityLevel: {
                    width: 120,
                    head: "资信"
                },
                GJJNum: {
                    width: 120,
                    head: "公积金帐号"
                },
                FundLoanPrice: {
                    width: 80,
                    head: "公贷金额(万)"
                },
                FundLoanEndYear: {
                    width: 80,
                    head: "公贷年限"
                },
                BuildingArea: {
                    width: 80,
                    head: "面积"
                },
                Total_Floor: {
                    width: 60,
                    head: "层高"
                },
                EvaluatePrice: {
                    width: 100,
                    head: "评估价(万)"
                },
                EvaluateCompany: {
                    width: 120,
                    head: "评估公司"
                },
                BusinessLoanPrice: {
                    width: 120,
                    head: "商业贷款(万)"
                },
                LoanBank: {
                    width: 100,
                    head: "贷款银行"
                },
                Prejudication: {
                    width: 300,
                    head: "预审意见"
                }
            }
        });
        return this.CompactGrid;
    },
    loadinfo: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentArchiveInfo = data;
                }
            }
        });
    },
    initEvent: function() {
        var _this = this;

        //        $('.tr_archive').live('click', function() {
        //            $('.tr_archive,.selected_orgbgcolor').each(function() {
        //                $(this).removeClass('selected_orgbgcolor');
        //            });
        //            $(this).toggleClass('selected_orgbgcolor');
        //            if (_this.currentId != this.id) {
        //                _this.currentId = this.id;
        //                _this.loadinfo();
        //            }
        //        });

        //        $('.tr_archive').live('mouseover', function() {
        //            $(this).toggleClass('orgbgcolor');
        //        });
        //        $('.tr_archive').live('mouseout', function() {
        //            $(this).toggleClass('orgbgcolor');
        //        });

        //修改报备
        $("A[name='aEditArchive']").live('click', function() {
            if ($(this).attr("val")) {
                _this.currentId = $(this).attr("val");
            }
            _this.editArchive();
        });

        //日常回复
        $("A[name='aDailyReply']").live('click', function() {
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.showDailyToReply();
        });

        //法务回复
        $("A[name='aLawReply']").live('click', function() {
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.showLawToReply();
        });

        //办证回复
        $("A[name='aApplyDocReply']").live('click', function() {
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.showApplyDocToReply();
        });

        //贷款回复
        $("A[name='aLoanReply']").live('click', function() {
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.showLoanToReply();
        });
        //作废报备
        $("A[name='aLapseArchive']").live('click', function() {
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.setCancelArchive();
        });
        //上传附件
        $("A[name='aUploadAttachment']").live('click', function() {
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.uploadAttachment();
        });
        //报备详情
        $("A[name='aArchiveDetail']").live('click', function() {
            if ($(this).attr("val")) {
                _this.currentId = $(this).attr("val");
            }
            if (!_this.currentId) {
                alert('请先选择一条报备记录！');
                return;
            }
            window.location.href = "ArchiveDetailInfo.aspx?RecordId=" + _this.currentId;
        });

        //日常回复列表
        $("A[name='aDailyReplyNum']").live('click', function() {
            _this.showDailyReplyList($(this).attr("val"));
        });

    },
    editArchive: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }

        Chenxin.Fn.checkPermit(_this.actionUrl, 'updarchive', function(data, msg) {
            if (data.permit != undefined) {
                _this.permit = data.permit;
                _this.msg = msg;
            }
        }, this, { modelid: _this.currentId });
        if (_this.permit) {
            window.location.href = "/page/Business_Record/ContractArchive.aspx?RecordId=" + _this.currentId + "";
        } else {
            alert(_this.msg);
        }

    },
    showDailyToReply: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        if (!this.DailyToReplyForm) {
            this.DailyToReplyForm = new Chenxin.UI.DailyToReplyForm({
                scrop: _this,
                alwaysCheckPermit: true,
                saveSucc: function() {
                    _this.grid.reload();
                    _this.currentId = null;
                }
            });
        }
        this.DailyToReplyForm.op = "savedailytoreply";
        if (this.DailyToReplyForm.show(this.DailyToReplyForm.op, { currentId: _this.currentId })) {
            this.DailyToReplyForm.reset();
            var _data = this.currentArchiveInfo;
            this.DailyToReplyForm.fitData(_data);
            this.DailyToReplyForm.setTitle('日常回复');
        }
    },
    showLoanToReply: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        if (!this.LoanToReplyForm) {
            this.LoanToReplyForm = new Chenxin.UI.LoanToReplyForm({
                scrop: _this,
                alwaysCheckPermit: true,
                saveSucc: function() {
                    _this.grid.reload();
                    _this.currentId = null;
                }
            });
        }
        this.LoanToReplyForm.op = "saveloantoreply";
        if (this.LoanToReplyForm.show(this.LoanToReplyForm.op, { currentId: _this.currentId })) {
            this.LoanToReplyForm.reset();
            var _data = this.currentArchiveInfo;
            _data.EvaluatePrice = _data.EvaluatePrice/10000;
            _data.FundLoanPrice = _data.FundLoanPrice/10000;
            _data.BusinessLoanPrice = _data.BusinessLoanPrice/10000;
            this.LoanToReplyForm.fitData(_data);
            this.LoanToReplyForm.setTitle('贷款回复');
        }
    },
    showLawToReply: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        if (!this.LawToReplyForm) {
            this.LawToReplyForm = new Chenxin.UI.LawToReplyForm({
                scrop: _this,
                alwaysCheckPermit: true,
                beforeSave: function() {
                    _this.op = "savelawtoreply";
                },
                saveSucc: function() {
                    _this.grid.reload();
                    _this.currentId = null;
                }
            });
        }
        this.LawToReplyForm.op = "savelawtoreply";
        if (this.LawToReplyForm.show(this.LawToReplyForm.op, { currentId: _this.currentId })) {
            this.LawToReplyForm.reset();
            var _data = this.currentArchiveInfo;
            this.LawToReplyForm.fitData(_data);
        }
        this.LawToReplyForm.setTitle('法务回复');
        $("#tr_law").show();
        $("#tr_applydoc").hide();
    },
    showApplyDocToReply: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        if (!this.LawToReplyForm) {
            this.LawToReplyForm = new Chenxin.UI.LawToReplyForm({
                scrop: _this,
                alwaysCheckPermit: true,
                beforeSave: function() {
                    _this.op = "saveapplydoctoreply";
                },
                saveSucc: function() {
                    _this.grid.reload();
                    _this.currentId = null;
                }
            });
        }
        this.LawToReplyForm.op = "saveapplydoctoreply";
        if (this.LawToReplyForm.show(this.LawToReplyForm.op, { currentId: _this.currentId })) {
            this.LawToReplyForm.reset();
            var _data = this.currentArchiveInfo;
            this.LawToReplyForm.fitData(_data);
        }
        this.LawToReplyForm.setTitle('办证回复');
        $("#tr_law").hide();
        $("#tr_applydoc").show();
    },
    setCancelArchive: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        if (!confirm("确定要作废此报备信息吗？")) {
            return false;
        }
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            url: this.actionUrl,
            data: { op: 'cancelarchive', modelid: _this.currentId },
            onSuccess: function(data, msg) {
                alert(msg);
                _this.grid.reload();
            }
        });
    },
    archiveDetail: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        window.location.href = "/page/Business_Record/ArchiveDetailInfo.aspx?RecordId=" + _this.currentId + "";

    },
    uploadAttachment: function() {
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        if (!this.UploadAttachmentForm) {
            this.UploadAttachmentForm = new Chenxin.UI.UploadAttachmentForm({
                scrop: _this,
                alwaysCheckPermit: true,
                saveSucc: function() {
                    _this.currentId = null;
                }
            });
        }
        this.UploadAttachmentForm.op = "uploadattachment";
        if (this.UploadAttachmentForm.show(this.UploadAttachmentForm.op, { currentId: _this.currentId })) {
            this.UploadAttachmentForm.reset();
            var _data = this.currentArchiveInfo;
            this.UploadAttachmentForm.fitData(_data);
            this.UploadAttachmentForm.setTitle('上传附件');
        }
    },
    showDailyReplyList: function(strid) {
        var _this = this;
        if (!this.DailyReplyListForm) {
            this.DailyReplyListForm = new Chenxin.UI.DailyReplyListForm({
                scrop: _this,
                alwaysCheckPermit: true
            });
        }
        this.DailyReplyListForm.op = "dailyreplylist";
        if (this.DailyReplyListForm.show(this.DailyReplyListForm.op, { currentId: _this.currentId })) {
            this.DailyReplyListForm.reset();
            this.DailyReplyListForm.setTitle('日常回复列表');

            if (!this.DailyReplyListGrid) {
                this.DailyReplyListGrid = new Chenxin.UI.JsonGrid({
                    actionUrl: this.actionUrl + '?op=searchdailyreplylist',
                    pageSize: 15,
                    param: { modelid: strid },
                    renderTo: 'dailyreplylist_table',
                    id: 'dailyreplylist',
                    hasTitle: false,
                    extensible: false,
                    sortStyle: 'local',
                    columns: {
                        CreateUserName: {
                            head: '回复人',
                            width: 60,
                            sortable: true
                        },
                        CreateTime: {
                            head: '回复时间',
                            width: 130,
                            sortable: true
                        },
                        AnswerContent: {
                            head: '回复内容',
                            width: 650,
                            sortable: true,
                            style: 'text-align:left'
                        }
                    },
                    hasCheckBox: false
                });
            }
            else {
                this.DailyReplyListGrid.reload({ modelid: strid });
            }
        }
    },
    initComponent: function() {
        Chenxin.UI.ShowListArchive.superclass.initComponent.call(this);
		this.searchGrid();
    }
}); 

/**
*查询面板
*/
Chenxin.UI.ShowListArchiveSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'archive_search',
    initEvent: function() {
        var _this = this;

        //查询按钮
        $('#btnSreach').click(function() {
            var data = _this.scope.search.getParamJson();
            //data.showtype = $("#hidshowtype").val();
            //_this.scope.reloadGrid(data);
            _this.scope.searchGrid(data);
        });
        //快速查询
        $('.a-qucik-search').click(function() {
            //_this.scope.reloadGrid({ op: 'search', showtype: $("#hidshowtype").val(), quicktype: this.id });
            _this.scope.grid.reload({ quicktype: this.id });
        });
        //传统表格模式
        $('#aTrdditionMode').click(function() {

            $("#tab_div_inbox2").show();
            $("#tab_div_inbox1").hide();
            $(".floatbottom").show();
            _this.scope.grid = _this.scope.TrdditionGrid;
            _this.scope.reloadGrid();
            _this.scope.currentId = null;
        });
        //紧凑模式
        $('#aCompactMode').click(function() {

            $("#tab_div_inbox1").show();
            $("#tab_div_inbox2").hide();
            $(".floatbottom").hide();
            _this.scope.grid = _this.scope.CompactGrid;
            _this.scope.reloadGrid();
            _this.scope.currentId = null;
        });
        //导出Excel
        $('#aExportExcel').click(function() {
            _this.scope.exportData();
            //alert('暂未开通！');
        });

        //换行变色
		/*10-27 edit by kimi
        $(".info").live('mouseover', function(event) {
            $(this).toggleClass("info_hover");
        });
        $(".info").live('mouseout', function(event) {
            $(this).toggleClass("info_hover");
        });

        $(".divDailyReply").live('mouseover', function(event) {
            $("#btnhover").show();
        });
        $(".divDailyReply").live('mouseout', function(event) {
            $("#btnhover").hide();
        });
		*/

        $('#ipt_keywords').defText({
            deftxt: '请输入房屋地址/房屋编号'
        });
		var curdate=new Date();
		$('#ipt_begintime').val(curdate.getFullYear() + '-'+(curdate.getMonth()+1) +'-1');
		if(curdate.getMonth()+1 == 12)
		    $('#ipt_endtime').val(curdate.getFullYear()+1 + '-1-1');
		else
		    $('#ipt_endtime').val(curdate.getFullYear() + '-'+(curdate.getMonth()+2) +'-1');
    },
    createComboList: function() {

        //时间选项
        var archivetime = new Chenxin.UI.Combo({
            containerId: '#Archivetime',
            tbxWidth: 45,
            colWidth: 80,
            addPleaseSelected: false,
            items: comboCommon.ArchivetimeType
        });
        //选择范围
        var PlaceType = new Chenxin.UI.Combo({
            containerId: '#PlaceType',
            tbxWidth: 45,
            colWidth: 80,
            addPleaseSelected: false,
            items: comboCommon.PlaceType
        });
        //状态
        var Status = new Chenxin.UI.Combo({
            containerId: '#Status',
            tbxWidth: 45,
            colWidth: 80,
			addPleaseSelected: false,
            items: comboCommon.trustStatus
        });

        //五级联Combo
        var combl = new Chenxin.UI.StructComboList({
			comboConfig:{
				business:{
					colWidth:90
				},
				departs:{
					colWidth:90,
					hasSearch:true,
					hasPage:true,
					pageSize:10
				}
			}
		});
        var structs = combl.comboList;
        structs.push(archivetime);
        structs.push(Status);
        structs.push(PlaceType);

        return structs;
    },

    initComponent: function() {
        Chenxin.UI.ShowListArchiveSearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
    this.ShowListArchive=new Chenxin.UI.ShowListArchive();
});